package com.example.badyloans.controller;

import com.example.badyloans.common.ReturnResult;
import com.example.badyloans.pojo.*;
import com.example.badyloans.servlet.TAccountFlowService;
import com.example.badyloans.servlet.TBankCardService;
import com.example.badyloans.servlet.TUserWalletService;
import com.example.badyloans.servlet.TWithdrawService;
import com.example.badyloans.util.PageSupport;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;

/**
 * @author 啊桥哦
 * @Description:
 * @date 2020-07-16 9:44
 */
@RestController
public class twithdraw {

    @Resource
    private TWithdrawService withdrawService;
    @Resource
    private TUserWalletService tUserWalletService;
    @Resource
    private TBankCardService tBankCardService;
    @Resource
    private TAccountFlowService tAccountFlowService;

    /**
     * 提现金额方法
     * @return
     */
    @PostMapping("user/withdraw/add")
    public ReturnResult withdrawadd(TWithdraw tWithdraw){
        if(StringUtils.isEmpty(tWithdraw)){
            return ReturnResult.fail("该对象为空");
        }

        ReturnResult returnResult=withdrawService.insertSelective(tWithdraw);
        return returnResult;

    }

    /**
     *流水分页查询
     * @param loginlog
     * @return
     */
    @PostMapping("user/accountflow/query")
    public ReturnResult accountflowquery(loginlog loginlog){
        PageSupport page=new PageSupport();
        page.setPageSize(2);
        page.setTotalCount(tAccountFlowService.count()); //查询总记录数
        page.setCurrentPageNo(loginlog.getCurrentPage());
        Integer pageSize=page.getPageSize();       //拿到页大小
        Integer currentPageNo=page.getCurrentPageNo(); //拿到页码
        List<TAccountFlow> list=tAccountFlowService.selectfenye(((currentPageNo-1)*pageSize),pageSize,loginlog.getBeginDate(),loginlog.getEndDate());
        if (list==null){
            return  ReturnResult.fail("没有数据");
        }
        return ReturnResult.success(list,page);
    }
}
